package com.dindang.checkline.mvp.ui.activity.adapter.costom;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dindang.checkline.R;
import com.dindang.checkline.app.utils.MyUtils;
import com.dindang.checkline.mvp.model.entity.ItemDetailEntity;
import com.dindang.checkline.mvp.model.entity.LineDetailEntity;
import com.longxi.gamer_base.utils.DateTimeUtils;

import java.util.Date;
import java.util.List;

public class LineDetailAdapter extends RecyclerView.Adapter<LineDetailAdapter.ViewHolder> {

    List<LineDetailEntity.OfficerCountBean> list;
    public LineDetailAdapter(List<LineDetailEntity.OfficerCountBean> list) {
        this.list = list;
    }
    LineDetailEntity.RecordBean record;

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.line_detail_item, parent, false);
        LineDetailAdapter.ViewHolder viewHolder = new LineDetailAdapter.ViewHolder(view);
        return viewHolder;
    }

    public void setFirst(LineDetailEntity.RecordBean record){
        this.record = record;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        LineDetailEntity.OfficerCountBean item = list.get(position);
        if(position==0){
            holder.one.setText("计划期间："+ DateTimeUtils.dateToYearMonthDayHour(new Date(record.getD_start())) +"至"+DateTimeUtils.dateToYearMonthDayHour(new Date(record.getD_end())));
            holder.two.setText("实际期间："+ DateTimeUtils.dateToYearMonthDayHour(new Date(record.getD_execute())) +"至"+DateTimeUtils.dateToYearMonthDayHour(new Date(record.getD_close())));
            String plan  =  MyUtils.getTimeDuration(DateTimeUtils.dateToTimestamp(DateTimeUtils.dateToYearMonthDayHour(new Date(record.getD_end())))-DateTimeUtils.dateToTimestamp(DateTimeUtils.dateToYearMonthDayHour(new Date(record.getD_start()))));
            String actual  =  MyUtils.getTimeDuration(DateTimeUtils.dateToTimestamp(DateTimeUtils.dateToYearMonthDayHour(new Date(record.getD_close())))-DateTimeUtils.dateToTimestamp(DateTimeUtils.dateToYearMonthDayHour(new Date(record.getD_execute()))));
            holder.three.setText("计划用时："+plan);
            holder.four.setText("实际用时："+actual);
            holder.five.setVisibility(View.GONE);
        }else{
            holder.one.setText("执行人员："+item.getOffcer_name());
            holder.two.setText("已完成巡检点："+item.getPerFinPointName()+"个，共"+item.getSumInsPointCount()+"个");
            holder.three.setText("已完成巡检项："+item.getPerFinPointItemExcName()+"个，共"+item.getSumInsPointIntmCount()+"个");
            holder.four.setText("已发现异常："+item.getPerFinPointItemExcName()+"个");
//            holder.five.setText("已生成故障报修："+"个");
//            holder.five.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        TextView one;
        TextView two;
        TextView three;
        TextView four;
        TextView five;
        ViewHolder(View itemView) {
            super(itemView);
            one = itemView.findViewById(R.id.one);
            two = itemView.findViewById(R.id.two);
            three = itemView.findViewById(R.id.three);
            four = itemView.findViewById(R.id.four);
            five = itemView.findViewById(R.id.five);
        }
    }
}